package ee.ut.sysmodel.bgmn.model;

public class Bar extends Pin {
	public static final int P2_BAR_POSITION = BoardState.PIN_COUNT + 1;
	public static final int P1_BAR_POSITION = 0;
	
	public Bar(Player player) {
		super(player.getIdentity() == Player.Identity.PLAYER_ONE ? P1_BAR_POSITION :
			P2_BAR_POSITION);
		
		pieceOwner = player;
	}
	
	@Override
	public int getPieceCount() {
		return pieceOwner.getBarCount();
	}
	
	@Override
	public boolean isOwned() {
		return true;
	}
	
	@Override
	public void removePiece() throws BackgammonException {
		if(getPieceCount() == 0)
			throw new BackgammonException("Can't remove a piece from the empty bar");
		
		pieceOwner.setBarCount(getPieceCount() - 1);
	}
	
	@Override
	public void setState(Player owner, int amount) {
		pieceOwner.setBarCount(amount);
	}
}
